<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<div class="layui-row layui-col-space15">

    <div class="layui-add-line"></div>
    <fieldset class="layui-elem-field layui-field-title" style="margin:0px;">
        <legend class="layui-add-title">变更信息</legend>
    </fieldset>


    <div class="layui-col-md12">
        <table class="layui-table" id="companyModifyTable" lay-filter="companyModifyTable">
            <thead>
            <tr>
                <th>变更内容</th>
                <th>变更前</th>
                <th>变更后</th>
                <th>变更时间</th>
                <th>变更机关</th>
                <th>操作员</th>
                <th lay-data="{field:'right',toolbar:'#barDemo',width:360}">变革材料</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${companyModifies}" var="info">
                <tr>
                    <td class="ellipsis-text" title="${info.content}">${info.content}</td>
                    <td class="ellipsis-short" title="${info.oldChange}">${info.oldChange}</td>
                    <td class="ellipsis-short" title="${info.newChange}">${info.newChange}</td>
                    <td><fmt:formatDate value="${info.createTime}" pattern="yyyy-MM-dd"/></td>
                    <td>${info.deptName}</td>
                    <td>${info.creator}</td>
                    <td>
                        <c:choose>
                            <c:when test="${not empty info.changeMaterials && info.changeMaterials != 'null'}">
                                <c:choose>
                                    <c:when test="${fn:startsWith(info.changeMaterials, '/files/')}">
                                        <c:set var="fileName"
                                               value="${fn:substringAfter(info.changeMaterials, '/files/')}"/>
                                        <a class="layui-btn layui-btn-sm"
                                           onclick="downloadFun('${info.changeMaterials}')">下载</a>
                                    </c:when>
                                    <c:otherwise>
                                        <span title="原始文件名: ${info.changeMaterials}">${info.changeMaterials}</span>
                                    </c:otherwise>
                                </c:choose>
                            </c:when>
                            <c:otherwise>
                                <span style="color: #999;">未上传</span>
                            </c:otherwise>
                        </c:choose>
                    </td>
                </tr>
            </c:forEach>
            <c:if test="${empty companyModifies}">
                <tr>
                    <td colspan="12" style="text-align: center;">没有数据</td>
                </tr>
            </c:if>
            </tbody>
        </table>
    </div>
</div>
<script>
    //下载文件
    function downloadFun(path) {
        const filename = path.replace('/files/', '');
        window.location.href = '${ctx}/managementSystem/download/' + filename;
    }

</script>